#include <windows.h>
#include "MD5.h"

//void MD5Init  ( MD5_CTX* context );
//void MD5Update( MD5_CTX context, unsigned char* input, unsigned int inlen );
//void MD5Final ( MD5_CTX context);

typedef void (WINAPI *F_MD5Init) 
( 
	MD5_CTX* context
); 

typedef void (WINAPI *F_MD5Update) 
( 
	MD5_CTX* context,
	unsigned char* input, 
	unsigned int inlen
); 

typedef void (WINAPI *F_MD5Final) 
( 
	MD5_CTX* context
); 


void CalcMD5(MD5_CTX *ctx, void *buffer,  int len)
{
	HINSTANCE lib;
	F_MD5Init   init;
	F_MD5Update update;
	F_MD5Final  final;

	lib = LoadLibrary(TEXT("Cryptdll.dll"));
	if ( lib )
	{
		init   = (F_MD5Init)  GetProcAddress(lib, "MD5Init");
		update = (F_MD5Update)GetProcAddress(lib, "MD5Update");
		final  = (F_MD5Final) GetProcAddress(lib, "MD5Final");
		
		if ( init && update && final )
		{
			(*init)(ctx);
			(*update)(ctx, (unsigned char*)buffer,len);
			(*final)(ctx);
		}

		FreeLibrary(lib);
	}
}